<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>在线平台</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
    <script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <style>
        body {
            font-family: "Lato", sans-serif;
        }

        .sidenav {
            height: 100%;
            width: 248px;
            position: fixed;
            z-index: 1;
            top: 0;
            left: 0;
            background-color: #f1f1f1;
            overflow-x: hidden;
            padding-top: 50px;
        }

        .sidenav a {
            margin-left: 16px;
            width: 215px;
            padding: 16px 16px 16px 16px;
            text-decoration: none;
            font-size: 25px;
            color: #000000;
            display: block;
            background-color: white;
            border: 52px #000000;
        }

        .sidenav a:hover {
            background-color: #2494ef;
            color: #f1f1f1;
        }

        .main {
            margin-left: 248px; /* 与sidenav的宽度相同 */
            font-size: 28px; /* 字体放大，让页面可滚动 */
            padding: 0px 10px;
        }

        @media screen and (max-height: 450px) {
            .sidenav {padding-top: 15px;}
            .sidenav a {font-size: 18px;}
        }
    </style>
</head>
<body style="background-color: #f1f1f1">
    <nav class="navbar navbar-default" role="navigation" style=" background-color:#2494ef; box-shadow: 0px 0px 6px #000; height: 50px;border: 0px">
        <div class="container-fluid">
            <div class="navbar-header">
                <a class="navbar-brand" href="index.html" style="color: white;">软件项目管理在线学习平台</a>
            </div>
            <div>
                <ul class="nav navbar-nav">
                    <li><a class="navbar-brand" href="TeaNavigationPage.html" style="color: white;font-size: 20px">| 课程</a></li>
                </ul>
            </div>
            <div style="margin-left: 1780px">
                <ul class="nav navbar-nav">
                    <li><a class="navbar-brand" href="TeaInfo.html" style="color: white;font-size: 20px">个人中心</a></li>
                </ul>
            </div>
        </div>
    </nav>
    <div class="panel panel-default" style="margin-left:auto;margin-right:auto;width:1600px">
        <div class="panel-body" style="font-size:25px">
            选择课程
        </div>
        <div class="panel-footer">
                <div class="row"></div>
        </div>
    </div>
</body>
<script>
    $.ajax({
        async:false,
        type:"GET",
        dataType: "json",
        url: 'course',
        error : function(XMLHttpRequest, textStatus, errorThrown) {
            console.log(XMLHttpRequest);
            console.log(textStatus);
            console.log(errorThrown);
        },
        success: function (response) {
            let $row = $(".row");
            let courses = response.data;
            for (let i in courses){
                let course = courses[i];
                let courseHtml = '<div class="col-sm-6 col-md-3">\n' +
                    '                <div class="thumbnail">\n' +
                    '                    <img src="course.jpg"\n' +
                    '                         alt="通用的占位符缩略图">\n' +
                    '                    <div class="caption">\n' +
                    '                        <h3>'+course['name']+'</h3>\n' +
                    '                        <p>'+course['description']+'</p>\n' +
                    '                        <p>\n' +
                    '                            <a href="TeaCourse.html" onclick="courseIntroduction('+course.id+')" class="btn btn-default" role="button">\n' +
                    '                                查看课程\n' +
                    '                            </a>\n' +
                    '                        </p>\n' +
                    '                    </div>\n' +
                    '                </div>\n' +
                    '            </div>';
                console.log($row);
                $row.append(courseHtml);
            }
        }
    });
    function courseIntroduction(courseId) {
        sessionStorage.setItem("courseId",courseId);
    }
</script>
</html>
